package com.ima.web.beans.db;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.ForeignKey;


@Entity
@Table(name="users")
public class Users {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="users_id")
	private Integer usersId;
	
	@Column(name="pen_name")
	private String penName;
	
	@Column(name="username")
	private String username;
	
	@Column(name="password")
	private String password;
	
	@Column(name="email")
	private String email;
	
	@Column(name="email2")
	private String email2;
	
	@Column(name="dob")
	private Date dob;
	
	@Column(name="last_login")
	private Date lastLogin;
	
	@Column(name="last_ip")
	private String lastIp;
	
	@Column(name="created_date")
	private Date createdDate;
	
	@Column(name="last_updated_date")
	private Date lastUpdatedDate;
	
	@Column(name="enabled")
	private Boolean enabled;
	
	@Fetch(FetchMode.SUBSELECT)
	@OneToMany(mappedBy="user",fetch=FetchType.EAGER)
	private List<Stories> stories;
	
	@Fetch(FetchMode.SUBSELECT)
	@OneToMany(mappedBy="approver",fetch=FetchType.EAGER)
	private List<SubCategories> approvedSubCategories;
	
	@Fetch(FetchMode.SUBSELECT)
	@OneToMany(mappedBy="approver",fetch=FetchType.EAGER)
	private List<Categories> approvedCategories;
	
	@OneToOne(fetch=FetchType.EAGER)
	//@PrimaryKeyJoinColumn(name="profile_id",referencedColumnName="profile_id")
	@JoinColumn(name="profile_id")
	private Profile profile;

	public Users(){
		enabled = true;
	}
	
	public Users(String username){
		this.username = username;
	}
	
	
	public List<SubCategories> getApprovedSubCategories() {
		return approvedSubCategories;
	}

	public void setApprovedSubCategories(List<SubCategories> approvedSubCategories) {
		this.approvedSubCategories = approvedSubCategories;
	}

	public List<Categories> getApprovedCategories() {
		return approvedCategories;
	}

	public void setApprovedCategories(List<Categories> approvedCategories) {
		this.approvedCategories = approvedCategories;
	}

	public int getUsersId() {
		return usersId;
	}
	
	
	public String getPenName() {
		return penName;
	}
	
	public String getUsername() {
		return username;
	}
	
	public String getPassword() {
		return password;
	}
	
	public String getEmail() {
		return email;
	}
	
	public String getEmail2() {
		return email2;
	}
	
	public Date getDob() {
		return dob;
	}
	
	public Date getLastLogin() {
		return lastLogin;
	}
	
	public String getLastIp() {
		return lastIp;
	}
	
	public Date getCreatedDate() {
		return createdDate;
	}
	
	public Date getLastUpdatedDate() {
		return lastUpdatedDate;
	}
	
	public boolean isEnabled() {
		return enabled;
	}
	
	public List<Stories> getStories() {
		return stories;
	}
	
	public void setUsersId(int usersId) {
		this.usersId = usersId;
	}
	public void setPenName(String penName) {
		this.penName = penName;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public void setEmail2(String email2) {
		this.email2 = email2;
	}
	public void setDob(Date dob) {
		this.dob = dob;
	}
	public void setLastLogin(Date lastLogin) {
		this.lastLogin = lastLogin;
	}
	public void setLastIp(String lastIp) {
		this.lastIp = lastIp;
	}
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}
	public void setLastUpdatedDate(Date lastUpdatedDate) {
		this.lastUpdatedDate = lastUpdatedDate;
	}
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public void setStories(List<Stories> stories) {
		this.stories = stories;
	}
	
	public Profile getProfile() {
		return profile;
	}

	public void setProfile(Profile profile) {
		this.profile = profile;
	}

	
}
